package com.homson.coreservice.serviceapp.transaction;

import com.homson.coreservice.serviceapi.query.TransactionQueryApi;
import com.homson.coreservice.servicecommon.request.PageRequestParameter;
import com.homson.coreservice.servicecommon.request.TransactionQueryRequest;
import com.homson.coreservice.servicecommon.response.EntityResponse;
import com.homson.coreservice.servicecommon.response.PageResponse;
import com.homson.coreservice.servicecommon.vo.TransactionVO;
import com.homson.servicedomain.domain.transaction.TransactionRenderCommand;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/8 3:27 PM
 **/
@Service
@Slf4j
public class TransactionQueryService implements TransactionQueryApi {
    
    @Resource
    private TransactionRenderCommand transactionRenderCommand;
    
    @Override
    public PageResponse<List<TransactionVO>> queryTransactionListRender(PageRequestParameter<TransactionQueryRequest> request) {
        Long userId = request.getBody().getUserId();
        try {
            List<TransactionVO> transactionVOS = transactionRenderCommand.transactionListRender(userId, request.getPage(), request.getSize());
            return PageResponse.ok(transactionVOS, request.getPage(), request.getSize());
        } catch (Exception e) {
            log.error(TransactionQueryService.class.getSimpleName(), e);
            return PageResponse.fail(e.getMessage());
        }
    }
}
